package com.lwl.blog.web.controller;

import com.lwl.blog.web.service.InvitationService;
import com.lwl.blog.web.service.UserService;
import com.lwl.blog.web.vo.IndexDataVo;
import com.lwl.blog.web.vo.MyPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;


@Controller
@RequestMapping("/indexController")
public class IndexController {

    //调用service层
    @Autowired
    private InvitationService invitataionService;

    @Autowired
    private UserService userService;

    @GetMapping("/index")
    public String index(MyPage<IndexDataVo> page, Integer order, ModelMap map) throws Exception {

        //添加一个默认排序
        if (order == null) {
            order = 1;
        }

        //1.获取数据
//      List<IndexDataVo> list = invitataionService.indexDataList(order);
        invitataionService.indexDataPage(page,order);

        // 2.放到Map中
        // 用户点击下一页的时候应该请求那个接口？
        page.setPath("/indexController/index");
        map.put("page", page);

//        //4.将它放到集合中
//        map.put("indexDateList", list);
        //5.然后转发到视图层处理
        return "view/index";
    }
}
